Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports C4F.DevKit.DesktopSearch
Namespace DesktopSearch
	Public Partial Class DesktopSearch
	Inherits Form
		#Region "Globle variable"
		'Use for storing previous tab name.
		Public lastTab As String
		'use for counting files while searching.
		Public count As Integer = 0
		'Use for storing tab name while changing tab.
		Public Tabname As String
		'''Creating object of DesktopSearchManager Class.
		Private desktopsearch As DesktopSearchManager = New DesktopSearchManager()
		#End Region
		#Region "Form initialization"
		''' <summary>
		''' Constructor. Keeps GUI in particular state at start.
		''' </summary>
		Public Sub New()
			InitializeComponent()
			grpAdvanceFileSearchOptions.Enabled = False

			InitializeAllTab()
			InitializePictureTab()
			InitializeMusicTab()
			InitializeEmailTab()
			InitializeMsOfficeTab()
			'Setting default root for folderBrowserDialog.
            fdSerach.RootFolder = System.Environment.SpecialFolder.Desktop
		End Sub
		''' <summary>
		''' Keeps controls of Tab-page 'All' in initial state.
		''' </summary>
		Public Sub InitializeAllTab()
			'Set Loction textBox as empty.
			txtAllLocation.Text = Nothing
			'Setting all combo box to zero Index.
			cmbAllDate.SelectedIndex = 1
			cmbAllDateCompare.SelectedIndex = 0
			cmbAllSize.SelectedIndex = 0
			CmbFileTypes.SelectedIndex = 0
			'clear all header of list view.
			lsvSearchResults.Columns.Clear()
			'Setting new Header to list view.
			lsvSearchResults.Columns.Add("File Name", 120)
			lsvSearchResults.Columns.Add("Location", 150)
			lsvSearchResults.Columns.Add("Author", 100)
			lsvSearchResults.Columns.Add("Size(B)", 100)
			lsvSearchResults.Columns.Add("Attribute", 100)
			lsvSearchResults.Columns.Add("Date Created", 100)
			lsvSearchResults.Columns.Add("Date Modified", 100)
			lsvSearchResults.Columns.Add("Title", 100)
			'Setting default value of last tab as All.
			lastTab = "All"
		End Sub
		''' <summary>
		''' Keeps controls of Tab-page 'Email' in initial state.
		''' </summary>
		Public Sub InitializeEmailTab()
			'Setting all combo box to zero Index.
			cmbEmailDate.SelectedIndex = 1
			cmbEmailDateCompare.SelectedIndex = 0
			cmbEmailSize.SelectedIndex = 0
			cmbEmailLocation.SelectedIndex = 0
			cmbEmailPriority.SelectedIndex = 0
		End Sub
		''' <summary>
		''' Keeps controls of Tab-page 'Picture' in initial state.
		''' </summary>
		Public Sub InitializePictureTab()
			'Setting all combo box to zero Index.
			cmbPictureDate.SelectedIndex = 1
			cmbPictureDateCompare.SelectedIndex = 0
			cmbPictureSize.SelectedIndex = 0
		End Sub
		''' <summary>
		''' Keeps controls of Tab-page 'Music' in initial state.
		''' </summary>
		Public Sub InitializeMusicTab()
			'Setting all combo box to zero Index.
			cmbMusicDate.SelectedIndex = 1
			cmbMusicDateCompare.SelectedIndex = 0
			cmbMusicSize.SelectedIndex = 0
		End Sub
		''' <summary>
		''' Keeps controls of Tab-page Document in initial state.
		''' </summary>
		Public Sub InitializeMsOfficeTab()
			'Setting all combo box to zero Index.
			cmbMsOfficeDate.SelectedIndex = 1
			cmbMsOfficeDateCompare.SelectedIndex = 0
			cmbMsOfficeSize.SelectedIndex = 0
			cmbMsOfficeFiles.SelectedIndex = 0
		End Sub
		#End Region
		#Region "Methods"
		''' <summary>
		''' File search method.
		''' </summary>
		Public Sub AllFileSearch()
			'''clear lable_count text.
			lblCount.Text = ""
			'''Creating object of FileSearchCriteria  Class.
			Dim fileSearchCriteria As FileSearchCriteria = New FileSearchCriteria()
			'Setting  propeties value of FileSearchCriteria for specifying search Criteria.
			fileSearchCriteria.FileAuthor = txtAllAuthor.Text
			fileSearchCriteria.FileType = DirectCast(CmbFileTypes.SelectedIndex, FileType)
			fileSearchCriteria.FileName = txtAllName.Text
			fileSearchCriteria.FileTag = txtAllTag.Text
			fileSearchCriteria.SearchLocation = txtAllLocation.Text
			fileSearchCriteria.FileDateFilter = DirectCast(cmbAllDate.SelectedIndex, FileDateFilter)
			fileSearchCriteria.DateCompareOption = DirectCast(cmbAllDateCompare.SelectedIndex, DateCompareOption)
			'''If date filter is not Any then set value for date. 
			If cmbAllDateCompare.SelectedIndex <> 0 Then
				fileSearchCriteria.[Date] = dtAll.Value
			End If
			fileSearchCriteria.SizeCompareOption = DirectCast(cmbAllSize.SelectedIndex, SizeCompareOption)
			'''If size text box is not empty then setting size value.
			If txtAllSize.Text <> String.Empty Then
				Dim size As Single = 0
				If Not [Single].TryParse(txtAllSize.Text, size) Then
					MessageBox.Show("Only integer is acceptable")
					Return
				End If
				fileSearchCriteria.Size = Convert.ToUInt32(Math.Round(size))
			End If
			'''If extension text box is not empty then setting extension value.
			If txtAllExtension.Text <> "" Then
				fileSearchCriteria.Extension = txtAllExtension.Text
			End If
			'''remove all items from list view.
			lsvSearchResults.Items.Clear()
			Try
				'''Calling search method.
				Dim files As List(Of FileInfo) = desktopsearch.Search(fileSearchCriteria)
				'''check if no result found.
				If files.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'''Setting FileInfo properties to ListView.
					For Each file As FileInfo In files
						Dim authorList As String = [String].Empty
						If file.Author IsNot Nothing Then
							For Each author As String In file.Author
								authorList += author + " ;"
							Next
						End If
						Dim fields As String() = New String() {file.Name, file.SearchLocation, authorList, file.Size.ToString(), file.Attributes.ToString(), file.DateCreated.ToShortDateString(), _ 
							file.DateModified.ToShortDateString(), file.Title}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					lblCount.Text = count.ToString() + " files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As ArgumentException
				'Catch and show ArgumentException.
				MessageBox.Show("Input is not valid !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		''' <summary>
		''' Music search method.
		''' </summary>
		Public Sub MusicSearch()
			'clear lable_count text.
			lblCount.Text = ""
			'Creating object of MusicSearchCriteria Class.
			Dim musicSearchCriteria As MusicSearchCriteria = New MusicSearchCriteria()
			'Setting  propeties value of MusicSearchCriteria for specifying search Criteria.
			musicSearchCriteria.AlbumName = txtMusicAlbum.Text
			musicSearchCriteria.ArtistName = txtMusicArtist.Text
			musicSearchCriteria.SearchLocation = txtMusicLocation.Text
			musicSearchCriteria.MusicTitle = txtMusicTitle.Text
			musicSearchCriteria.MusicDateFilter = DirectCast(cmbMusicDate.SelectedIndex, MusicDateFilter)
			musicSearchCriteria.DateCompareOption = DirectCast(cmbMusicDateCompare.SelectedIndex, DateCompareOption)
			'If date filter is not Any then set value for date. 
			If cmbMusicDateCompare.SelectedIndex <> 0 Then
				musicSearchCriteria.[Date] = dtMusic.Value
			End If
			musicSearchCriteria.SizeCompareOption = DirectCast(cmbMusicSize.SelectedIndex, SizeCompareOption)
			'If size text box is not empty then setting size value.
			If txtMusicSize.Text <> String.Empty Then
				Dim size As Single = 0
				If Not [Single].TryParse(txtMusicSize.Text, size) Then
					MessageBox.Show("Only integer is acceptable")
					Return
				End If
				musicSearchCriteria.Size = Convert.ToUInt32(Math.Round(size))
			End If
			'''If extension text box is not empty then setting extension value.
			If txtMusicExtension.Text <> "" Then
				musicSearchCriteria.Extension = txtMusicExtension.Text
			End If
			'remove all items from list view.
			lsvSearchResults.Items.Clear()
			Try
				'Calling search method.
				Dim musics As List(Of MusicInfo) = desktopsearch.Search(musicSearchCriteria)
				'check if no result found.
				If musics.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'Setting FileInfo properties to ListView.
					For Each music As MusicInfo In musics
						Dim artistList As String = [String].Empty
						If music.Artists IsNot Nothing Then
							For Each artist As String In music.Artists
								artistList += artist + "; "
							Next
						End If
						Dim fields As String() = New String() {music.Name, music.Album, artistList, music.SearchLocation, music.Size.ToString(), music.Rating.ToString(), _ 
							music.Attributes.ToString()}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					lblCount.Text = count.ToString() + " music files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As ArgumentException
				'Catch and show ArgumentException.
				MessageBox.Show("Input is not valid !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		''' <summary>
		''' Picture search method.
		''' </summary>
		Public Sub PictureSearch()
			'clear lable_count text.
			lblCount.Text = ""
			'Creating object of PictureSearchCriteria Class.
			Dim pictureSearchCriteria As PictureSearchCriteria = New PictureSearchCriteria()
			pictureSearchCriteria.PictureName = txtPictureName.Text
			pictureSearchCriteria.SearchLocation = txtPictureLocation.Text
			pictureSearchCriteria.PictureTag = txtPictureTag.Text
			pictureSearchCriteria.PictureTitle = txtPictureTitle.Text
			pictureSearchCriteria.PictureDateFilter = DirectCast(cmbPictureDate.SelectedIndex, PictureDateFilter)
			pictureSearchCriteria.DateCompareOption = DirectCast(cmbPictureDateCompare.SelectedIndex, DateCompareOption)
			'If date filter is not Any then set value for date. 
			If cmbPictureDateCompare.SelectedIndex <> 0 Then
				pictureSearchCriteria.[Date] = dtPicture.Value
			End If
			pictureSearchCriteria.SizeCompareOption = DirectCast(cmbPictureSize.SelectedIndex, SizeCompareOption)
			'If size text box is not empty then setting size value.
			If txtPictureSize.Text <> String.Empty Then
				Dim size As Single = 0
				If Not [Single].TryParse(txtPictureSize.Text, size) Then
					MessageBox.Show("Only integer is acceptable")
					Return
				End If
				pictureSearchCriteria.Size = Convert.ToUInt32(Math.Round(size))
			End If
			'''If extension text box is not empty then setting extension value.
			If txtPictureExtension.Text <> "" Then
				pictureSearchCriteria.Extension = txtPictureExtension.Text
			End If
			'remove all items from list view.
			lsvSearchResults.Items.Clear()
			Try
				'Calling search method.
				Dim pictures As List(Of PictureInfo) = desktopsearch.Search(pictureSearchCriteria)
				'check if no result found.
				If pictures.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'Setting FileInfo properties to ListView.
					For Each picture As PictureInfo In pictures
						'Local variable for storing dateTaken set as empty.
						Dim dateTaken As String = String.Empty
						'Checks if dateTaken is not 01/01/0001.
						If Not picture.DateTaken.ToShortDateString().Equals("01-01-0001") Then
							dateTaken = picture.DateTaken.ToShortDateString()
						End If
						Dim tagList As String = [String].Empty
						If picture.Tags IsNot Nothing Then
							For Each tag As String In picture.Tags
								tagList += tag + "; "
							Next
						End If
						Dim fields As String() = New String() {picture.Name, picture.SearchLocation, dateTaken, picture.Size.ToString(), tagList, picture.Rating.ToString(), _ 
							picture.Attributes.ToString()}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					'sets file count to label.
					lblCount.Text = count.ToString() + " files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As ArgumentException
				'Catch and show ArgumentException.
				MessageBox.Show("Input is not valid !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		''' <summary>
		''' Email search method.
		''' </summary>
		Public Sub EmailSearch()
			'clear lable_count text.
			lblCount.Text = ""
			Dim emailSearchCriteria As EmailSearchCriteria = New EmailSearchCriteria()
			'Setting  propeties value of EmailSearchCriteria for specifying search Criteria.
			If cmbEmailLocation.SelectedIndex = 0 Then
				'Set serch location for All Index.
				emailSearchCriteria.SearchLocation = "Personal folders"
			Else
				emailSearchCriteria.SearchLocation = cmbEmailLocation.SelectedItem.ToString()
			End If
			emailSearchCriteria.EmailTo = txtEmailTo.Text
			emailSearchCriteria.EmailFrom = txtEmailFrom.Text
			emailSearchCriteria.EmailSubject = txtEmailSubject.Text
			emailSearchCriteria.EmailDateFilter = DirectCast(cmbEmailDate.SelectedIndex, EmailDateFilter)
			emailSearchCriteria.DateCompareOption = DirectCast(cmbEmailDateCompare.SelectedIndex, DateCompareOption)
			emailSearchCriteria.EmailAttachments = txtAttachments.Text
			Dim priority As Integer = cmbEmailPriority.SelectedIndex
			If priority > 1 Then
				Select priority
					Case 2
						priority = 3
						Exit Select
					Case 3
						priority = 5
						Exit Select
				End Select
			End If
			emailSearchCriteria.Priority = Ctype(priority, EmailPriority)
			'If date filter is not Any then set value for date. 
			If cmbEmailDateCompare.SelectedIndex <> 0 Then
				emailSearchCriteria.[Date] = dtEmail.Value
			End If
			emailSearchCriteria.SizeCompareOption = DirectCast(cmbEmailSize.SelectedIndex, SizeCompareOption)
			'If size text box is not empty then setting size value.
			If txtEmailSize.Text <> String.Empty Then
				Dim size As Single = 0
				If Not [Single].TryParse(txtEmailSize.Text, size) Then
					MessageBox.Show("Only integer is acceptable")
					Return
				End If
				emailSearchCriteria.Size = Convert.ToUInt32(Math.Round(size))
			End If
			'remove all items from list view.
			lsvSearchResults.Items.Clear()
			Try
				'Calling search method.
				Dim emails As List(Of EmailInfo) = desktopsearch.Search(emailSearchCriteria)
				'check if no result found. 
				If emails.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'Setting FileInfo properties to ListView.
					For Each email As EmailInfo In emails
						Dim attachmentList As String = [String].Empty
						If email.Attachments IsNot Nothing Then
							For Each attachment As String In email.Attachments
								attachmentList += attachment + "; "
							Next
						End If
						Dim toList As String = [String].Empty
						If email.ToList IsNot Nothing Then
							For Each id As String In email.ToList
								toList += id + "; "
							Next
						End If
						Dim hasAttachments As String = "No"
						If email.HasAttachments Then
							hasAttachments = "Yes"
						End If
						Dim fields As String() = New String() {email.From, email.Subject, email.DateReceived.ToShortDateString(), toList, email.Size.ToString(), hasAttachments, _ 
							attachmentList, email.Priority.ToString()}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					'sets file count to label.
					lblCount.Text = count.ToString() + " files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As ArgumentException
				'Catch and show ArgumentException.
				MessageBox.Show("Input is not valid !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		''' <summary>
		'''Document search method.
		''' </summary>
		Public Sub MsOfficeFileSearch()
			'clear lable_count text.
			lblCount.Text = ""
			'Creating object of FileSearchCriteria  Class.
			Dim fileSearchCriteria As FileSearchCriteria = New FileSearchCriteria()
			'Setting  propeties value of FileSearchCriteria for specifying search Criteria.
			fileSearchCriteria.FileAuthor = txtMsOfficeAuthor.Text
			fileSearchCriteria.FileType = DirectCast((cmbMsOfficeFiles.SelectedIndex + 1), FileType)
			fileSearchCriteria.FileName = txtMsOfficeName.Text
			fileSearchCriteria.FileTag = txtMsOfficeTag.Text
			fileSearchCriteria.SearchLocation = txtMsOfficeLocation.Text
			fileSearchCriteria.FileDateFilter = DirectCast(cmbMsOfficeDate.SelectedIndex, FileDateFilter)
			fileSearchCriteria.DateCompareOption = DirectCast(cmbMsOfficeDateCompare.SelectedIndex, DateCompareOption)
			'If date filter is not Any then set value for date. 
            If cmbMsOfficeDateCompare.SelectedIndex <> 0 Then
                fileSearchCriteria.[Date] = dtMsOffice.Value
            End If
			fileSearchCriteria.SizeCompareOption = DirectCast(cmbMsOfficeSize.SelectedIndex, SizeCompareOption)
			'If size text box is not empty then setting size value.
			If txtMsOfficeSize.Text <> String.Empty Then
				Dim size As Single = 0
				If Not [Single].TryParse(txtMsOfficeSize.Text, size) Then
					MessageBox.Show("Only integer is acceptable")
					Return
				End If
				fileSearchCriteria.Size = Convert.ToUInt32(Math.Round(size))
			End If
			'remove all items from list view.
			lsvSearchResults.Items.Clear()
			Try
				'Calling search method.
				Dim files As List(Of FileInfo) = desktopsearch.Search(fileSearchCriteria)
				'check if no result found.
				If files.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'Setting FileInfo properties to ListView.
					For Each file As FileInfo In files
						Dim authorList As String = [String].Empty
						If file.Author IsNot Nothing Then
							For Each author As String In file.Author
								authorList += author + "; "
							Next
						End If
						Dim fields As String() = New String() {file.Name, file.SearchLocation, authorList, file.Size.ToString(), file.Attributes.ToString(), file.DateCreated.ToShortDateString(), _ 
							file.DateModified.ToShortDateString(), file.Title}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					'sets file count to label.
					lblCount.Text = count.ToString() + " files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As ArgumentException
				'Catch and show ArgumentException.
				MessageBox.Show("Input is not valid !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		''' <summary>
		'''Files search by file name.
		''' </summary>
		Public Sub FileSearch()
			'''clear lable_count text.
			lblCount.Text = ""
			' Get file name specified in input.
			Dim fileName As String = txtFileName.Text
			Try
				'''Calling search method.
				Dim files As List(Of FileInfo) = desktopsearch.Search(fileName)
				'''check if no result found.
				If files.Count = 0 Then
					lblCount.Text = "No files found !"
				Else
					count = 0
					'''Setting FileInfo properties to ListView.
					For Each file As FileInfo In files
						Dim authorList As String = [String].Empty
						If file.Author IsNot Nothing Then
							For Each author As String In file.Author
								authorList += author + " ;"
							Next
						End If
						Dim fields As String() = New String() {file.Name, file.SearchLocation, authorList, file.Size.ToString(), file.Attributes.ToString(), file.DateCreated.ToShortDateString(), _ 
							file.DateModified.ToShortDateString(), file.Title}
						'Creating new listview item.
						Dim item As ListViewItem = New ListViewItem(fields)
						'Adds new item to listview.
						lsvSearchResults.Items.Add(item)
						'Increment counter.
						count += 1
					Next
					lblCount.Text = count.ToString() + " files found !"
				End If
			Catch ex As ArgumentNullException
				'Catch and show ArgumentNullException.
				MessageBox.Show("Input can not be null !")
				Dim exception As String = ex.ToString()
			Catch ex As DesktopSearchException
				'Catch and show DesktopSearchException
				MessageBox.Show("Error ! Search can not be perform")
				Dim exception As String = ex.ToString()
			End Try
		End Sub
		#End Region
		#Region "Event"
		#Region "Tab change event"
		''' <summary>
		''' Keeps controle on tab change event.
		''' </summary>
        Private Sub tabControl_search_Selected(ByVal sender As Object, ByVal e As TabControlEventArgs) Handles tbSearch.Selected
            'Takes tab name.
            Tabname = e.TabPage.Name
            'Sets listview headers and default settings for tab.
            Select Case Tabname
                Case "Email"
                    'remove all items from list view.
                    lsvSearchResults.Items.Clear()
                    'clear all header of list view.
                    lsvSearchResults.Columns.Clear()
                    'Setting new Header to list view.
                    lsvSearchResults.Columns.Add("From", 120)
                    lsvSearchResults.Columns.Add("Subject", 100)
                    lsvSearchResults.Columns.Add("Date Receive", 100)
                    lsvSearchResults.Columns.Add("To Name", 180)
                    lsvSearchResults.Columns.Add("Size(B)", 100)
                    lsvSearchResults.Columns.Add("Has Attachment", 100)
                    lsvSearchResults.Columns.Add("Attachments", 100)
                    lsvSearchResults.Columns.Add("Priority", 100)
                    Exit Select
                Case "All"
                    'remove all items from list view.
                    lsvSearchResults.Items.Clear()
                    'clear all header of list view.
                    lsvSearchResults.Columns.Clear()
                    'Setting new Header to list view.
                    lsvSearchResults.Columns.Add("File Name", 120)
                    lsvSearchResults.Columns.Add("Location", 150)
                    lsvSearchResults.Columns.Add("Author", 100)
                    lsvSearchResults.Columns.Add("Size(B)", 100)
                    lsvSearchResults.Columns.Add("Attribute", 100)
                    lsvSearchResults.Columns.Add("Date Created", 100)
                    lsvSearchResults.Columns.Add("Date Modified", 100)
                    lsvSearchResults.Columns.Add("Title", 100)
                    'set loction value form preivious tab.
                    Select Case lastTab
                        Case "Music"
                            txtAllLocation.Text = txtMusicLocation.Text
                            Exit Select
                        Case "Picture"
                            txtAllLocation.Text = txtPictureLocation.Text
                            Exit Select
                        Case "Document"
                            txtAllLocation.Text = txtMsOfficeLocation.Text
                            Exit Select
                    End Select
                    'Sets last tab as current tab.
                    lastTab = "All"
                    Exit Select
                Case "Music"
                    'remove all items from list view.
                    lsvSearchResults.Items.Clear()
                    'clear all header of list view.
                    lsvSearchResults.Columns.Clear()
                    'Setting new Header to list view.
                    lsvSearchResults.Columns.Add("Name", 120)
                    lsvSearchResults.Columns.Add("Album Name", 120)
                    lsvSearchResults.Columns.Add("Artist Name", 100)
                    lsvSearchResults.Columns.Add("Location", 150)
                    lsvSearchResults.Columns.Add("Size(B)", 100)
                    lsvSearchResults.Columns.Add("Rating", 100)
                    lsvSearchResults.Columns.Add("Attribute", 100)
                    'set loction value form preivious tab.
                    Select Case lastTab
                        Case "All"
                            txtMusicLocation.Text = txtAllLocation.Text
                            Exit Select
                        Case "Picture"
                            txtMusicLocation.Text = txtPictureLocation.Text
                            Exit Select
                        Case "Document"
                            txtMusicLocation.Text = txtMsOfficeLocation.Text
                            Exit Select
                    End Select
                    'Sets last tab as current tab.
                    lastTab = "Music"
                    Exit Select
                Case "Picture"
                    'remove all items from listview.
                    lsvSearchResults.Items.Clear()
                    'clear all header of listview.
                    lsvSearchResults.Columns.Clear()
                    'Setting new Header to listview.
                    lsvSearchResults.Columns.Add("Name", 120)
                    lsvSearchResults.Columns.Add("Location", 150)
                    lsvSearchResults.Columns.Add("Date Taken", 100)
                    lsvSearchResults.Columns.Add("Size(B)", 100)
                    lsvSearchResults.Columns.Add("Tag", 100)
                    lsvSearchResults.Columns.Add("Rating", 100)
                    lsvSearchResults.Columns.Add("Attribute", 100)
                    'Set loction value form preivious tab.
                    Select Case lastTab
                        Case "All"
                            txtPictureLocation.Text = txtAllLocation.Text
                            Exit Select
                        Case "Music"
                            txtPictureLocation.Text = txtMusicLocation.Text
                            Exit Select
                        Case "Document"
                            txtPictureLocation.Text = txtMsOfficeLocation.Text
                            Exit Select
                    End Select
                    'Sets last tab as current tab.
                    lastTab = "Picture"
                    Exit Select
                Case "Document"
                    'remove all items from listview.
                    lsvSearchResults.Items.Clear()
                    'clear all header of listview.
                    lsvSearchResults.Columns.Clear()
                    'Setting new Header to listview.
                    lsvSearchResults.Columns.Add("File Name", 120)
                    lsvSearchResults.Columns.Add("Location", 150)
                    lsvSearchResults.Columns.Add("Author", 100)
                    lsvSearchResults.Columns.Add("Size(B)", 100)
                    lsvSearchResults.Columns.Add("Attribute", 100)
                    lsvSearchResults.Columns.Add("Date Created", 100)
                    lsvSearchResults.Columns.Add("Date Modified", 100)
                    lsvSearchResults.Columns.Add("Title", 100)
                    'listViewSearchResults.w
                    'set loction value form preivious tab.
                    Select Case lastTab
                        Case "Music"
                            txtMsOfficeLocation.Text = txtMusicLocation.Text
                            Exit Select
                        Case "Picture"
                            txtMsOfficeLocation.Text = txtPictureLocation.Text
                            Exit Select
                        Case "All"
                            txtMsOfficeLocation.Text = txtAllLocation.Text
                            Exit Select
                    End Select
                    'Sets last tab as current tab.
                    lastTab = "Document"
                    Exit Select
            End Select
        End Sub
		#End Region
		#Region "Enable or disable Datetime picker"
		''' <summary>
		''' Enable or disable Datetime picker for all file search.
		''' When date compare is any then makes it disable.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub cmbAllDateCompare_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbAllDateCompare.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbAllDateCompare.SelectedIndex = 0 Then
                dtAll.Enabled = False
            Else
                dtAll.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Enable or disable Datetime picker for Email search.
		''' When date compare is any then makes it disable.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_email_dateCompare_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbEmailDateCompare.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbEmailDateCompare.SelectedIndex = 0 Then
                dtEmail.Enabled = False
            Else
                dtEmail.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Enable or disable Datetime picker for Document search.
		''' When date compare is any then makes it disable.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_document_dateCompare_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMsOfficeDateCompare.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbMsOfficeDateCompare.SelectedIndex = 0 Then
                dtMsOffice.Enabled = False
            Else
                dtMsOffice.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Enable or disable Datetime picker for Picture search.
		''' When date compare is any then makes it disable.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_picture_datecompare_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbPictureDateCompare.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbPictureDateCompare.SelectedIndex = 0 Then
                dtPicture.Enabled = False
            Else
                dtPicture.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Enable or disable Datetime picker for Music search.
		''' When date compare is any then makes it disable.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_music_datecompare_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMusicDateCompare.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbMusicDateCompare.SelectedIndex = 0 Then
                dtMusic.Enabled = False
            Else
                dtMusic.Enabled = True
            End If
        End Sub
		#End Region
		#Region "Enable or disable Size TextBox"
		''' <summary>
		''' Keeps control on enable or disable Size textBox for All File search.
		''' If size index is zero then makes it disale and set null value to size textbox.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub cmbAllSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbAllSize.SelectedIndexChanged
            'check if selected index is 0. 
            If cmbAllSize.SelectedIndex = 0 Then
                txtAllSize.Text = Nothing
                txtAllSize.Enabled = False
            Else
                txtAllSize.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Keeps control on enable or disable Size textBox for Email search.
		''' If size index is zero then makes it disale and set null value to size text box.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_email_size_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbEmailSize.SelectedIndexChanged
            If cmbEmailSize.SelectedIndex = 0 Then
                txtEmailSize.Text = Nothing
                txtEmailSize.Enabled = False
            Else
                txtEmailSize.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Keeps control on enable or disable Size textBox for Document search.
		''' If size index is zero then makes it disale and set null value to size textbox.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_document_size_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMsOfficeSize.SelectedIndexChanged
            If cmbMsOfficeSize.SelectedIndex = 0 Then
                txtMsOfficeSize.Text = Nothing
                txtMsOfficeSize.Enabled = False
            Else
                txtMsOfficeSize.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Keeps control on enable or disable Size textBox for Picture search.
		''' If size index is zero then makes it disale and set null value to text box.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_picture_size_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbPictureSize.SelectedIndexChanged
            If cmbPictureSize.SelectedIndex = 0 Then
                txtPictureSize.Text = Nothing
                txtPictureSize.Enabled = False
            Else
                txtPictureSize.Enabled = True
            End If
        End Sub
		''' <summary>
		''' Keeps control on enable or disable Size textBox for Music search.
		''' If size index is zero then makes it disale and set null value to text box.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
        Private Sub comboBox_music_size_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMusicSize.SelectedIndexChanged
            If cmbMusicSize.SelectedIndex = 0 Then
                txtMusicSize.Text = Nothing
                txtMusicSize.Enabled = False
            Else
                txtMusicSize.Enabled = True
            End If
        End Sub
		#End Region
		#Region "Button click event for searching."
		'''Search button click event for file Search by only file name.
        Private Sub btnSearchFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchFile.Click
            lsvSearchResults.Items.Clear()
            Try
                'Set cursor as wait cursor.
                Windows.Forms.Cursor.Current = Cursors.WaitCursor
                'Calling FileSearch method.
                FileSearch()
                'Set cursor as default cursor.
                Windows.Forms.Cursor.Current = Cursors.[Default]
            Catch
                'Set cursor as default cursor.
                Windows.Forms.Cursor.Current = Cursors.[Default]
            End Try
        End Sub
		'''Search button click event for all files Search.
        Private Sub btnSearchAll_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchAll.Click
            'check textbox value of size is not empty when size compare option selected.
            If cmbAllSize.SelectedIndex <> 0 AndAlso txtAllSize.Text.Equals(String.Empty) Then
                MessageBox.Show("Please Enter size !")
                Return
            Else
                Try
                    'Set cursor as wait cursor.
                    Windows.Forms.Cursor.Current = Cursors.WaitCursor
                    'Calling AllFileSearch method.
                    AllFileSearch()
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                Catch
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                End Try
            End If
        End Sub
		'''Search button click event for Music Search.
        Private Sub btnSearchMusic_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchMusic.Click
            'check textbox value of size is not empty when size compare option selected.
            If cmbMusicSize.SelectedIndex <> 0 AndAlso txtMusicSize.Text.Equals(String.Empty) Then
                MessageBox.Show("Please Enter size !")
                Return
            Else
                Try
                    'Set cursor as wait cursor.
                    Windows.Forms.Cursor.Current = Cursors.WaitCursor
                    'Calling MusicSearch method.
                    MusicSearch()
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                Catch
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                End Try
            End If
        End Sub
		'''Search button click event for email Search.
        Private Sub btnEmail_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchEmail.Click
            'check textbox value of size is not empty when size compare option selected.
            If cmbEmailSize.SelectedIndex <> 0 AndAlso txtEmailSize.Text.Equals(String.Empty) Then
                MessageBox.Show("Please Enter size !")
                Return
            Else
                Try
                    'Set cursor as wait cursor.
                    Windows.Forms.Cursor.Current = Cursors.WaitCursor
                    'Calling EmailSearch method.
                    EmailSearch()
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                Catch
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                End Try
            End If
        End Sub
		'''Search button click event for picture Search.
        Private Sub btnSearchPicture_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchPicture.Click
            'check textbox value of size is not empty when size compare option selected.
            If cmbPictureSize.SelectedIndex <> 0 AndAlso txtPictureSize.Text.Equals(String.Empty) Then
                MessageBox.Show("Please Enter size !")
                Return
            Else
                Try
                    'Set cursor as wait cursor.
                    Windows.Forms.Cursor.Current = Cursors.WaitCursor
                    'Calling PictureSearch method.
                    PictureSearch()
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                Catch
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                End Try
            End If
        End Sub
		'''Search button click event for MS office file Search.
        Private Sub btnSearchMsOffice_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearchMsOffice.Click
            'check textbox value of size is not empty when size compare option selected.
            If cmbMsOfficeSize.SelectedIndex <> 0 AndAlso txtMsOfficeSize.Text.Equals(String.Empty) Then
                MessageBox.Show("Please Enter size !")
                Return
            Else
                Try
                    'Set cursor as wait cursor.
                    Windows.Forms.Cursor.Current = Cursors.WaitCursor
                    'Calling DocumentSearch method.
                    MsOfficeFileSearch()
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                Catch
                    'Set cursor as default cursor.
                    Windows.Forms.Cursor.Current = Cursors.[Default]
                End Try
            End If
        End Sub
		#End Region
#Region "Select Loction Button click Event"
        '''Set loction from FolderBrowser to textbox  for All tab.
        Private Sub btnAllLoction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAllLoction.Click
            fdSerach.ShowDialog()
            txtAllLocation.Text = fdSerach.SelectedPath
        End Sub

        '''Set loction from FolderBrowser to textbox  for MSOffice tab.
        Private Sub btnMsOfficeLocation_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsOfficeLocation.Click
            fdSerach.ShowDialog()
            txtMsOfficeLocation.Text = fdSerach.SelectedPath
        End Sub
        '''Set loction from FolderBrowser to textbox  for Music tab.
        Private Sub btnMusicLocation_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMusicLocation.Click
            fdSerach.ShowDialog()
            txtMusicLocation.Text = fdSerach.SelectedPath
        End Sub
        '''Set loction from FolderBrowser to textbox  for Picture tab.
        Private Sub btnPictureLocation_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPictureLocation.Click
            fdSerach.ShowDialog()
            txtPictureLocation.Text = fdSerach.SelectedPath
        End Sub
        '''Set loction from FolderBrowser to textbox  for Document tab.
        'Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMsOfficeLocation.Click
        '    fdSerach.ShowDialog()
        '    txtMsOfficeLocation.Text = fdSerach.SelectedPath
        'End Sub
#End Region
		#Region "Enable or disable DateCompare ComboBox when date is None"
		''' <summary>
		''' Keeps Control on activating and deactivating DateCompare ComboBox if date is None.
		''' </summary>
		'Activating and deactivating DateCompare ComboBox for All.
        Private Sub cmbAllDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbAllDate.SelectedIndexChanged
            If cmbAllDate.SelectedIndex = 0 Then
                cmbAllDateCompare.SelectedIndex = 0
                cmbAllDateCompare.Enabled = False
            Else
                cmbAllDateCompare.Enabled = True
            End If
        End Sub
		'Activating and deactivating DateCompare ComboBox for Email.
        Private Sub comboBoxEmailDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbEmailDate.SelectedIndexChanged
            If cmbEmailDate.SelectedIndex = 0 Then
                cmbEmailDateCompare.SelectedIndex = 0
                cmbEmailDateCompare.Enabled = False
            Else
                cmbEmailDateCompare.Enabled = True
            End If
        End Sub
		'Activating and deactivating DateCompare ComboBox for Document.
        Private Sub comboBoxDocumentDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMsOfficeDate.SelectedIndexChanged
            If cmbMsOfficeDate.SelectedIndex = 0 Then
                cmbMsOfficeDateCompare.SelectedIndex = 0
                cmbMsOfficeDateCompare.Enabled = False
            Else
                cmbMsOfficeDateCompare.Enabled = True
            End If
        End Sub
		'Activating and deactivating DateCompare ComboBox for Picture.
        Private Sub comboBoxPictureDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbPictureDate.SelectedIndexChanged
            If cmbPictureDate.SelectedIndex = 0 Then
                cmbPictureDateCompare.SelectedIndex = 0
                cmbPictureDateCompare.Enabled = False
            Else
                cmbPictureDateCompare.Enabled = True
            End If
        End Sub
		'Activating and deactivating DateCompare ComboBox for Music.
        Private Sub comboBoxMusicDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMusicDate.SelectedIndexChanged
            If cmbMusicDate.SelectedIndex = 0 Then
                cmbMusicDateCompare.SelectedIndex = 0
                cmbMusicDateCompare.Enabled = False
            Else
                cmbMusicDateCompare.Enabled = True
            End If
        End Sub
		#End Region
		#Region "check box check event for selecting advanced search for files."
		'''Set search options for specfic type like email, picture and music etc if checked
		'''otherwise faciliates searching performed by only file name.
        Private Sub chkAdvancedSearch_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkAdvancedSearch.CheckedChanged
            If chkAdvancedSearch.Checked = True Then
                txtFileName.Text = ""
                txtFileName.Enabled = False
                btnSearchFile.Enabled = False
                grpAdvanceFileSearchOptions.Enabled = True
            Else
                'Setting new Header to list view.
                lsvSearchResults.Columns.Clear()
                lsvSearchResults.Columns.Add("File Name", 120)
                lsvSearchResults.Columns.Add("Location", 150)
                lsvSearchResults.Columns.Add("Author", 100)
                lsvSearchResults.Columns.Add("Size(B)", 100)
                lsvSearchResults.Columns.Add("Attribute", 100)
                lsvSearchResults.Columns.Add("Date Created", 100)
                lsvSearchResults.Columns.Add("Date Modified", 100)
                lsvSearchResults.Columns.Add("Title", 100)
                'Setting default value of last tab as All.
                lastTab = "All"
                txtFileName.Enabled = True
                btnSearchFile.Enabled = True
                grpAdvanceFileSearchOptions.Enabled = False
            End If
        End Sub
		#End Region
		#End Region


       
        
    End Class


   


End Namespace


